<template>
  <transition name="down">
    <div v-show="show"
         :style="style[type]"
         class="msg">
      <i :class="`iconfont icon-${style[type].icon}`"/>
      {{ text }}
    </div>
  </transition>
</template>

<script lang="ts"
        setup>
import {onMounted, ref} from 'vue'
import type {Style} from './type'
import {StyleType} from './type'

let emits = defineEmits<{
  (e: 'update:modelValue', v: boolean): void
}>()

let props = withDefaults(defineProps<{
  text?: string
  type?: StyleType
}>(), {
  text: '',
  type: StyleType.success
})

let show = ref<boolean>(false)
onMounted(() => {
  show.value = true
})

const style: Style = {
  warn: {
    icon: 'warning',
    color: '#E6A23C',
    backgroundColor: 'rgb(253, 246, 236)',
    borderColor: 'rgb(250, 236, 216)'
  },
  error: {
    icon: 'shanchu',
    color: '#F56C6C',
    backgroundColor: 'rgb(254, 240, 240)',
    borderColor: 'rgb(253, 226, 226)'
  },
  success: {
    icon: 'queren2',
    color: '#67C23A',
    backgroundColor: 'rgb(240, 249, 235)',
    borderColor: 'rgb(225, 243, 216)'
  }
}
</script>

<style lang="less"
       scoped>
.msg {
  z-index: 9999;
  position: fixed;
  background-color: white;
  top: 25px;
  left: 50%;
  margin-left: -150px;
  width: 300px;
  height: 40px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  padding-left: 30px;

  i {
    margin-right: 4px;
    margin-top: 2px;
  }
}

.down {
  &-enter {
    &-from {
      transform: translate3d(0, -75px, 0);
      opacity: 0;
    }

    &-active {
      transition: all 0.5s;
    }

    &-to {
      transform: none;
      opacity: 1;
    }
  }
}
</style>